﻿@using KRM.Core
@using Kybotech.Paragon
@{
    ViewBag.Title = "SelectDeliveryDate";
    Layout = "~/Views/Shared/_PopupLayout.cshtml";
    NewOrderData data = ViewBag.data;
    var selectedVisit = data.SelectedVisit ?? data.CurrentVisits.FirstOrDefault() ?? new Visit();
    ViewBag.lstNotParagonOrderItems = new SelectList(data.NotParagonOrderItems.Select(f => "(" + f.ItemHistory + ") " + f.ProductName + " - " + f.ProductOption).ToList());
    
}
<script>
    $(document).ready(function () {
        $("#tree li ul li div,#tree li div").click(function () {
            $(this).addClass("list-selected");
            $("#tree li ul li div").not(this).removeClass('list-selected');
            $("#tree li div").not(this).removeClass('list-selected');
        });
        SelectedVisitChanged('@(selectedVisit.OrderCode)', 1,@selectedVisit.VisitNum,'@(selectedVisit.VisitDate > DateTime.MinValue?selectedVisit.VisitDate.ToShortDateString():"")');
    });
</script>
<div id="ReasonForRemoveVisit" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" data-width="400">
    <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
        <h4>Enter Reason</h4>
    </div>
    <div class="modal-body">
        <div class="row-fluid">
            <label class="span12 control-label">
                You wish to amend the Paragon date? Please enter a reason!
            </label>
            <div class="span12">
                <textarea id="txtReasonForRemoveVisit" class="input-block-level" rows="5"></textarea>
            </div>
        </div>
    </div>
    <div class="modal-footer">
        <input type="hidden" id="ActionReasonForRemoveVisit" value="" />
        <button class="btn btn-default" data-dismiss="modal" aria-hidden="true">Close</button>
        <button type="button" class="btn btn-success" onclick="ConfirmReasonForRemoveVisit()">Confirm</button>
    </div>
</div>

<div style="padding: 10px">
    <div class="row-fluid">
        <div class="span4">
            <div class="row-fluid">
                <p style="font-weight: bold; font-size: larger">Paragon items</p>
                <div class="row-fluid">
                    <div class="span4">Selected Visit: </div>
                    <label id="selectedOrderCode" class="span8" style="font-weight: bold;">@selectedVisit.OrderCode</label>
                </div>
                <input type="hidden" id="selectedVisitCode" value="@selectedVisit.OrderCode"/>
                <input type="hidden" id="IsSelectedVisitTree" value="1" />
                <input type="hidden" id="selectedVisitNum" value="@selectedVisit.VisitNum"/>
                <input type="hidden" id="selectedVisitDate" value=""/>
                <div class="row-fluid">Grouped visit</div>
                <div style="height: 150px; width: 100%; border: 1px solid black; overflow: auto">
                    <div>
                        <ul id="tree" style="list-style-type: square;">
                            @foreach (var item in data.CurrentVisits)
                            {
                                <li  onclick=" SelectedVisitChanged('@item.OrderCode',1,@item.VisitNum,'@(item.VisitDate > DateTime.MinValue?item.VisitDate.ToString("dd/MM/yyyy"):"")') " style="cursor: pointer" >
                                    <div class="@(selectedVisit.OrderCode == item.OrderCode ? "list-selected" : "")">@item.OrderCode@(item.VisitDate > DateTime.MinValue ? " -" + @item.VisitDate.ToString("dd/MM/yyyy") : "")</div>
                                </li>
                                <ul style="list-style-type: circle;">
                                    @foreach (var productItem in item.Products)
                                    {
                                        <li onclick=" SelectedGroupedItemChanged(@productItem.SKU, @productItem.Quantity); SelectedVisitChanged('@item.OrderCode',0); "style="cursor: pointer">
                                            <div>@productItem.Description  - @productItem.Service (@productItem.Quantity)</div>
                                        </li>
                                    }
                                </ul>
                            }
                        </ul>
                    </div>
                </div>
            </div>
            <div class="row-fluid" style="margin-top: 10px; margin-bottom: 5px; overflow: auto;">
                <a class="btn" onclick="AddNewVisit()" title="Add new visit" data-placement="right">
                    <img src="/img/delivery_newvisit.png" /></a>
                <a class="btn" onclick="RemoveVisit()" title="Remove visit" data-placement="right">
                    <img src="/img/delivery_removevisit.png" /></a>
                <a class="btn" onclick="AutoGroupItems()" title="Auto group visit" data-placement="right">
                    <img src="/img/delivery_sort.png" /></a>
                <a class="btn" onclick="AddItemToVisit()" title="Add item to visit" data-placement="right">
                    <img src="/img/delivery_addtovisit.png" /></a>
                <a class="btn" onclick="DeleteVisitItem()" title="Remove item" data-placement="right" style="display: none">
                    <img src="/img/delivery_remove.png" /></a>
            </div>

            <div class="row-fluid">
                <p style="font-weight: bold;">Ungrouped order item</p>
                <div style="height: 150px; width: 100%; border: 1px solid black; overflow: auto">
                    <table class="table table-bordered  tbl-orderitemdetail floatThead-table">
                        <thead>
                            <tr>
                                <th>Item</th>
                                <th>Vehicle</th>
                            </tr>
                        </thead>
                        <tbody>
                            @foreach (tblOrderItem item in data.NotGroupedOrderItems)
                            {
                                <tr onclick=" SelectedUngroupItemChanged(@item.OrderItemID)">
                                    <td>@item.ProductOption</td>
                                    <td>@item.VehicleCode()</td>
                                </tr>
                            }
                        </tbody>
                    </table>
                </div>
            </div>
            <div class="row-fluid">
                <p style="font-weight: bold; font-size: larger">Boxed Items</p>
                <div style="height: 150px; width: 100%; border: 1px solid black; overflow: auto">
                    <table class="table table-bordered  tbl-orderitemdetail floatThead-table">
                        <thead>
                            <tr>
                                <th>Product name</th>
                                <th>Delivery Date</th>
                            </tr>
                        </thead>
                        <tbody>
                            @foreach (tblOrderItem item in data.BoxOrderItems)
                            {
                                <tr  onclick=" SelectedBoxItemChanged(@item.OrderItemID) ">
                                    <td>@item.ProductName</td>
                                    <td>@item.EstDeliveryDate.ToString("MM/dd/yyyy")</td>
                                </tr>
                            }
                        </tbody>
                    </table>
                </div>
            </div>
            <div class="row-fluid">
                <p style="font-weight: bold; font-size: larger">PYD Unavailable</p>
                These items are not available for picking a delivery date
            <div style="height: 100px; width: 100%; border: 1px solid black;">
                @Html.ListBox("lstNotParagonOrderItems", null, new { style = "height: 100%;width: 100%;" })
            </div>
            </div>
        </div>
        <div class="span8" id="VisitDetail">
            @Html.Action("GetVisitInfo", selectedVisit)
        </div>
    </div>
</div>
